package com.hxd.otc.dialog;

import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;

import com.hxd.otc.R;

/**
 * 包  名 :  com.hxd.otc.widget
 * 类  名 :  DealMeunPopupWindow
 * 作  者 :  胡庆岭
 * 时  间 :  2018/6/7 14:50
 * 描  述 :  ${TODO}
 */
public class DealMenuPopupWindow extends PopupWindow {
    private View mContentView;
    private int mWidth;
    private int mHeight;
    private PopupWindow mPopupWindow;

    public DealMenuPopupWindow(@NonNull View contentView, int width, int height) {
        this.mContentView = contentView;
        this.mWidth = width;
        this.mHeight = height;
        initView();
    }

    private void initView() {
        if (mPopupWindow == null) {
            mPopupWindow = new PopupWindow(mContentView, mWidth, mHeight);
            mPopupWindow.setBackgroundDrawable(ContextCompat.getDrawable(mContentView.getContext(), R.color.color_80000000));
            mPopupWindow.setOutsideTouchable(true);
            mPopupWindow.setTouchable(true);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void show(@NonNull View view) {
        mPopupWindow.showAsDropDown(view, 0, 0, Gravity.CENTER_HORIZONTAL);
    }

}
